//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __FAT12_H_
#define __FAT12_H_

typedef UInt16 fat12_t;    /* A 12-bit FAT value */

class fat12
{
public:
    virtual int fat12_init(class fatfs_sharedata *pSharedata);
    virtual void fat12_sync(void);
    virtual struct clust * fat12_alloc(struct clust *c, struct directory *d);
    virtual int fat12_setlen(struct clust *c, UInt32 newclust);
    virtual int fat12_loadfat(class fatfs_sharedata *pSharedata);
    virtual UInt64 fat12_calcfreespace();
#if defined(_DEBUG)
    void fat12_stat(UInt32 *Fat_secs);
#endif
    fat12();
    virtual ~fat12();

    class fatfs_sharedata *p_Sharedata;
private:
    void dirty(UInt32 idx);
    void set(UInt32 idx, fat12_t val);
    fat12_t get(UInt32 idx);

    UInt8 *fat;         /* Our in-core FAT */
    UInt32 fatlen;        /* Length in bytes */
    UInt8 *dirtymap;    /* Map of sectors with dirty FAT entries */
    UInt32 dirtymapsize;  /*  ...size of map */
    UInt32 nxt_clust;     /* Where last cluster search left off */
};

/*------------------------------------------------------------------------*/
/* Values for FAT slots                                                   */
/*------------------------------------------------------------------------*/
#define FAT12_RESERVED (0xFF0)    /* Start of reserved value range */
#define FAT12_DEFECT (0xFF7)    /* Cluster w. defective block */
#define FAT12_EOF (0xFF8)        /* Start of EOF range */
#define FAT12_END (0xFFF)        /* End of reserved range */

#endif //__FAT12_H_
